﻿using Db7_ut.DomainObjects;
using System.Collections.Generic;
using Db7;

namespace Db7_ut.Views.Tables
{
    public class ScrollingTable
    {
        EmployeeList _employees;
        List<Column> _columns = new List<Column>();
        string _ContainerID;

        public ScrollingTable(string ContainerID)
        {

            this._ContainerID = ContainerID;
            this._employees = new EmployeeList();
            this._employees.Populate(OnPopulate);

           
            
        }

        public void OnPopulate()
        {
            #region Column Model

            Column colID = new Column(); _columns.Add(colID);
            colID.HeaderText = "ID";
            colID.RowIndexToBodyCellContent = delegate(int ithRow)
            {
                return this._employees.Employees[ithRow].ID;
            };
            #endregion
            //VirtualElement veParent = new VirtualElement(); veParent.Tag = "div";
            
            
            VTable table = new VTable(); 
            table.Columns = _columns;
            table.NumberOfRows_D = this._employees.Employees.Count;
            table.PageSize_D = 5;
            
            VScrollbar scrollbar = new VScrollbar(); 
            scrollbar.ScrollValue_DB = new IntBinder(0);
            scrollbar.MaxValue = table.NumberOfRows_D;
            scrollbar.DimensionsNN.Height = 100;
            table.StartingRow_DB = scrollbar.ScrollValue_DB;

            VInput textBox = new VInput();
            textBox.Value_DB = new StringBinder(null);
            textBox.Value_DB.SetIntInnerBinder(scrollbar.ScrollValue_DB);

            VirtualElement tblParent = new VirtualElement(); tblParent.Tag = "table";
            VirtualElement tblBody = new VirtualElement(); tblBody.Tag = "tbody"; tblParent.ChildrenNN.Add(tblBody);
            VirtualElement tblRow = new VirtualElement(); tblRow.Tag = "tr"; tblBody.ChildrenNN.Add(tblRow);
            VirtualElement tblCellLHS = new VirtualElement(); tblCellLHS.Tag = "td"; tblRow.ChildrenNN.Add(tblCellLHS);
            VirtualElement tblCellMid = new VirtualElement(); tblCellMid.Tag = "td"; tblRow.ChildrenNN.Add(tblCellMid);
            VirtualElement tblCellRHS = new VirtualElement(); tblCellRHS.Tag = "td"; tblRow.Children.Add(tblCellRHS);
            tblCellLHS.ChildrenNN.Add(table);
            tblCellMid.ChildrenNN.Add(textBox);
            tblCellRHS.ChildrenNN.Add(scrollbar);
            tblParent.RenderInside(_ContainerID);
        }
    }
}
